package org.ellisande.grid.tags;

import java.util.EnumSet;

import javax.servlet.jsp.JspWriter;

import org.ellisande.grid.tags.support.TagBuilder;
import org.ellisande.tld.annotations.Attribute;
import org.ellisande.tld.annotations.Description;
import org.ellisande.tld.annotations.EvaluateExpressions;
import org.ellisande.tld.annotations.Info;
import org.ellisande.tld.annotations.Required;
import org.ellisande.tld.annotations.Tag;

@Tag
@Info("Defines a group of buttons.")
public class ButtonGroupTag extends AbstractTag {

	private static final long serialVersionUID = 4407345573470091283L;

	private static enum Type {
		GROUP("btn-group"), TOOLBAR("btn-toolbar");

		private String type;

		private Type(String type) {
			this.type = type;
		}

		public String toString() {
			return type;
		}
	}

	@Attribute
	@Required
	@EvaluateExpressions
	@Description("Defines the type of button group that will be rendered. Allowed values: group | toolbar")
	private Type type = Type.GROUP;

	

	public void setType(String type) {
		for (Type currentType : EnumSet.allOf(Type.class)) {
			if (currentType.name().equalsIgnoreCase(type)) {
				this.type = currentType;
				return;
			}
		}

		this.type = Type.GROUP;
	}

	@Override
	public void startTag() throws Exception {
		TagBuilder div = createTagBuilder("div");
		div.addStyle(type.toString());

		JspWriter out = pageContext.getOut();
		out.println(div.compileStartTag());
	}

	@Override
	public void endTag() throws Exception {
		TagBuilder div = createTagBuilder("div");
		JspWriter out = pageContext.getOut();
		out.println(div.compileEndTag());
	}
}
